<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>ECharts Example</title>
  <script src="https://cdn.jsdelivr.net/npm/echarts@5.1.2/dist/echarts.min.js"></script>
</head>
<body>
  <div id="chart" style="width: 800px; height: 600px;"></div>

  <script>
    var chart = echarts.init(document.getElementById('chart'));

    var data = [
      { city: '北京', price: 100, decoration: '毛坯' },
      { city: '上海', price: 200, decoration: '精装修' },
      { city: '广州', price: 150, decoration: '毛坯' },
      { city: '深圳', price: 180, decoration: '精装修' },
      { city: '成都', price: 120, decoration: '毛坯' }
    ];

    var option = {
      title: {
        text: '商品房价格与装修情况',
        left: 'center'
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: ['毛坯', '精装修']
      },
      xAxis: {
        type: 'category',
        data: data.map(item => item.city)
      },
      yAxis: {
        type: 'value',
        name: '价格'
      },
      series: [
        {
          name: '毛坯',
          type: 'bar',
          stack: '装修情况',
          itemStyle: {
            color: '#FF7F50' // 设置毛坯柱状图颜色
          },
          data: data.filter(item => item.decoration === '毛坯').map(item => item.price)
        },
        {
          name: '精装修',
          type: 'bar',
          stack: '装修情况',
          itemStyle: {
            color: '#87CEEB' // 设置精装修柱状图颜色
          },
          data: data.filter(item => item.decoration === '精装修').map(item => item.price)
        }
      ]
    };

    chart.setOption(option);
  </script>
</body>
</html>
